//@author A0096466N
//
// **********
//
// storage class handles everything to do with
// the txt file storage such as 
//		reading from txt
//		writing to txt
//		rewriting txt
//
// **********

#include "Storage.h"

Storage::Storage(void) {
	
}

Storage::~Storage(void) {

}

void Storage::getStorage(vector<string> & store) {
	ofstream writeFile;
	writeFile.open(FILENAME_LOGGER.c_str(), ofstream::out | ofstream::app);
	writeFile << "Attempting to read from txt storage" << endl;
	writeFile.close();
	
	ifstream readFile;
	readFile.open(FILENAME_SCHEDULE.c_str());

	string data;
	while(getline(readFile,data)) {
		store.push_back(data);
	}
	return;
}

void Storage::addTask(string data) {
	ofstream writeFile;
	writeFile.open(FILENAME_LOGGER.c_str(), ofstream::out | ofstream::app);
	writeFile << "Attempting to add to txt storage" << endl;
	writeFile.close();

	ofstream outStream;
	outStream.open(FILENAME_SCHEDULE.c_str(), ofstream::out | ofstream::app);
	outStream << data << endl;
	outStream.close();

	return;
}
	
void Storage::rewrite(vector <string> store) {
	ofstream writeFile;
	writeFile.open(FILENAME_LOGGER.c_str(), ofstream::out | ofstream::app);
	writeFile << "Attempting to rewrite txt storage" << endl;
	writeFile.close();
	
	ofstream outStream(FILENAME_SCHEDULE.c_str());
	
	for(unsigned int i = 0; i < store.size(); i++) {
		outStream << store[i] << endl;
	}
	outStream.close();
	return;
}
